#!/usr/bin/perl -w

use strict;
use warnings;
use diagnostics;

use Getopt::Std;


our($opt_h,$opt_p,$opt_n);
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my $wgcmd = "/usr/bin/wgcmd";

getopts('h:p:');

unless ($opt_h && $opt_p) {
    &usage;
    exit -1;
}

# do our work


#my $args = "$wgcmd -u status -p '$opt_p' $opt_h status /system/tasks pcpu=1 | grep \'$opt_n\'";

my $buf  = `/usr/bin/sshpass -p readwrite ssh -p 4118 root\@$opt_h "cat /proc/sys/net/ipv4/netfilter/ip_conntrack_count"`; 

if ($?>>8 > 0) {
    print "error: sshpass call ssh to execute command failed\n";
    exit -1;
}
# my $mem_total = 0;
# my $mem_free = 0;

# if ($buf =~ m/MemTotal:\s+(\d+)\s+kB/) {
#     $mem_total = $1;
#     $mem_total =~ s/^\s+//;
#     $mem_total =~ s/\s+$//;
#     #print "$cpu_percent";
# } 

# if ($buf =~ m/MemFree:\s+(\d+)\s+kB/) {
#     $mem_free= $1;
#     $mem_free =~ s/^\s+//;
#     $mem_free =~ s/\s+$//;
#     #print "$cpu_percent";
# } 

$buf =~ s/\n//g;

if ($buf != 0){
    print "$buf";
}else{
    print "U";
}

sub usage {
    print "Usage: $0 -h <host> -p <root pass> #>\n"; 
}
